package hbnu;

import java.util.Scanner;

public class test6 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int people =sc.nextInt();
        int [] p=new int[people];
        for(int i=0;i<people;i++){
            p[i]=1;
        }
        int x=0;
        int count=0;
        int remain=people;
        while(remain!=1){
            if(p[x]==1)
                count++;
            if(count==3){
                p[x]=0;
                remain--;
                count=0;
            }
            x=(x+1)%people;
        }
        for(int i=0;i<people;i++){
            if(p[i]==1){
                System.out.println("最后的人是："+(i+1));
                break;
            }
        }
    }
}
